package com.itheima.userdemo.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    private static final String QUEUE_NAME = "UserQueue";
    //2.Queue 队列
    @Bean("UserQueue")
    public Queue bootQueue(){
        return QueueBuilder
                .durable(QUEUE_NAME)
//                .withArgument("x-message-ttl", 25000)
                .build();
    }
    @Bean("DelayExchange_dle")
    public Exchange DelayExchange_dle(){
        return ExchangeBuilder.fanoutExchange("DelayExchange_dle").durable(true).build();
    }
    @Bean("DelayExchange")
    public Exchange DelayExchange(){
        return ExchangeBuilder.fanoutExchange("DelayExchange").durable(true).build();
    }

    @Bean("DelayQueue")
    public  Queue DelayQueue(){
        return QueueBuilder.durable("DelayQueue").withArgument("x-message-ttl",20000).withArgument("x-dead-letter-exchange","DelayExchange_dle").build();
    }
    @Bean("DelayQueue_dle")
    public  Queue DelayQueue_dle(){
        return QueueBuilder.durable("DelayQueue_dle").build();
    }
    @Bean
    public Binding fanoutBinding1(@Qualifier("DelayQueue") Queue queue, @Qualifier("DelayExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("delayMessage").noargs();
    }
    @Bean
    public Binding dleBinding(@Qualifier("DelayQueue_dle") Queue queue, @Qualifier("DelayExchange_dle") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("DelayQueue_dle").noargs();
    }
}
